package com.xzw.service.impl;

import com.xzw.mapper.EmpMapper;
import com.xzw.mapper.StudentMapper;
import com.xzw.pojo.JobOption;
import com.xzw.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 统计员工职位人数
     */
    @Override
    public JobOption getEmpJobData() {
        // 1.调取mapper接口，获取统计数据
        List<Map<String, Object>> list = empMapper.countEmpJobData();
        // 2.组装结果，并返回
        List<Object> jobList = list.stream().map(dataMap -> dataMap.get("pos")).toList();
        List<Object> dataList = list.stream().map(dataMap -> dataMap.get("num")).toList();
        return new JobOption(jobList, dataList);
    }
    /**
     * 统计员工性别人数
     */
    @Override
    public List<Map<String, Object>> getEmpGenderData() {
        return empMapper.countEmpGenderData();
    }
    /**
     * 学员学历统计
     */
    @Override
    public List<Map<String, Object>> getStudentDegreeData() {
        return studentMapper.countStudentDegreeData();
    }
    /**
     * 班级人数统计
     */
    @Override
    public Map<String, Object> getStudentCountData() {
        List<Map<String, Object>> rawData = studentMapper.countStudentCountData();

        // 分离 clazzList 和 dataList
        List<String> clazzList = new ArrayList<>();
        List<Integer> dataList = new ArrayList<>();

        for (Map<String, Object> entry : rawData) {
            clazzList.add((String) entry.get("clazzList"));
            dataList.add(((Number) entry.get("dataList")).intValue()); // 确保是整数
        }

        // 构造符合接口文档格式的 Map
        Map<String, Object> responseData = new HashMap<>();
        responseData.put("clazzList", clazzList);
        responseData.put("dataList", dataList);

        return responseData;
    }


}
